import constants from '@/api/constants/index';

export default {
  namespaced: true,

  state: {
    constants: {}
  },

  mutations: {
    setConstants: (state, data) => {
      state.constants = data;
    }
  },

  actions: {
    find: (context) => {
      if(JSON.stringify(context.state.constants) === '{}') {
        return constants.find().then((data) => {
          let code = parseInt(data.code);
          if(code !== 0) { return {code:code,msg:data.msg}; }

          context.commit('setConstants', data.constants);

          return {code: code};
        });
      }

      return {code: 0};
    }
  }
};
